/* eslint-disable */
/**
 * home模块接口列表
 */

import baseUrl from './baseUrl' // 导入接口域名列表
import axios from '@/utils/http' // 导入http中创建的axios实例
import qs from 'qs' // 根据需求是否导入qs模块
import { getStore } from '@/assets/js/mUtils'

axios.defaults.withCredentials = true // 让ajax携带cookie

const home = {  

    // 获取定位城市
    cityGuess () {        
        return axios.get(`${baseUrl.sq}/v1/cities`, {
            params: {
                type: 'guess'
            }
        });
    },
     
    // 获取首页热门城市
    hotcity () {        
        return axios.get(`${baseUrl.sq}/v1/cities`, {
            params: {
                type: 'hot'
            }
        });
    },
     
    // 获取首页所有城市
    groupcity () {        
        return axios.get(`${baseUrl.sq}/v1/cities`, {
            params: {
                type: 'group'
            }
        });
    },
     
    // 获取所选城市信息
    currentcity (number) {        
        return axios.get(`${baseUrl.sq}/v1/cities/${number}`);
    },
     
    // 获取搜索地址
    searchplace (cityid, value) {        
        return axios.get(`${baseUrl.sq}/v1/pois`, {
            params: {
                type: 'search',
                city_id: cityid,
                keyword: value
            }
        });
    },
     
    // 根据经纬度详细定位
    homeAddress (geohash) {        
        return axios.get(`${baseUrl.sq}/v2/pois/${geohash}`);
    },
     
    // 获取食品分类列表
    homeFoodTypes (geohash) {        
        return axios.get(`${baseUrl.sq}/v2/index_entry`, {
            params: {
                geohash,
                group_type: 1,
                'flags[]': 'F'
            }
        });
    },
     
    // 获取商铺列表
    shopList (latitude, longitude, offset, restaurant_category_id = '', restaurant_category_ids = '', order_by = '', delivery_mode = '', support_ids = []) {        
        let supportStr = '';
        support_ids.forEach(item => {
            if (item.status) {
                supportStr += '&support_ids[]=' + item.id;
            }
        });
        let data = {
            latitude,
            longitude,
            offset,
            limit: '20',
            'extras[]': 'activities',
            keyword: '',
            restaurant_category_id,
            'restaurant_category_ids[]': restaurant_category_ids,
            order_by,
            'delivery_mode[]': delivery_mode + supportStr
        };
        return axios.get(`${baseUrl.sq}/shopping/restaurants`, {
            params: data
        });
    },
     
    // 搜索餐馆
    searchRestaurant (geohash, keyword) {        
        return axios.get(`${baseUrl.sq}/v4/restaurants`, {
            params: {
                'extras[]': 'restaurant_activity',
                geohash,
                keyword,
                type: 'search'
            }
        });
    },
     
    // 获取food页面的分类列表
    foodCategory (latitude, longitude) {        
        return axios.get(`${baseUrl.sq}/shopping/v2/restaurant/category`, {
            params: {
                latitude,
                longitude
            }
        });
    },
     
    // 获取food页面的配送方式
    foodDelivery (latitude, longitude) {        
        return axios.get(`${baseUrl.sq}/shopping/v1/restaurants/delivery_modes`, {
            params: {
                latitude,
                longitude,
                kw: ''
            }
        });
    },
     
    // 获取food页面的商家属性活动列表
    foodActivity (latitude, longitude) {        
        return axios.get(`${baseUrl.sq}/shopping/v1/restaurants/activity_attributes`, {
            params: {
                latitude,
                longitude,
                kw: ''
            }
        });
    },
     
    // 获取shop页面餐馆详情
    shopDetails (shopid, latitude, longitude) {        
        return axios.get(`${baseUrl.sq}/shopping/restaurant/${shopid}`, {
            params: {
                latitude,
                longitude: longitude + '&extras[]=activities&extras[]=album&extras[]=license&extras[]=identification&extras[]=statistics'
            }
        });
    },
     
    // 获取shop页面食品列表
    foodMenu (restaurant_id) {        
        return axios.get(`${baseUrl.sq}/shopping/v2/menu`, {
            params: {
                restaurant_id
            }
        });
    },
     
    // 获取餐馆评价信息
    getRatingList (shopid, offset, tag_name = '') {        
        return axios.get(`${baseUrl.sq}/ugc/v2/restaurants/${shopid}/ratings`, {
            params: {
                has_content: true,
                offset,
                limit: 10,
                tag_name
            }
        });
    },
     
    // 获取餐馆评价分数
    ratingScores (shopid) {        
        return axios.get(`${baseUrl.sq}/ugc/v2/restaurants/${shopid}/ratings/scores`);
    },
     
    // 获取餐馆评价分类
    ratingTags (shopid) {        
        return axios.get(`${baseUrl.sq}/ugc/v2/restaurants/${shopid}/ratings/tags`);
    },
     
    // 获取图片验证码
    getcaptchas () {        
        return axios.post(`${baseUrl.sq}/v1/captchas`, {});
    },
     
    // 获取短信验证码
    mobileCode (phone) {        
        return axios.post(`${baseUrl.sq}/v4/mobile/verify_code/send`, {
            mobile: phone,
            scene: 'login',
            type: 'sms'
        });
    },
     
    // 检测帐号是否存在
    checkExsis (checkNumber, type) {        
        return axios.get(`${baseUrl.sq}/v1/users/exists`, {
            params: {
                [type]: checkNumber,
                type
            }
        });
    },
     
    // 发送帐号
    sendMobile (sendData, captcha_code, type, password) {        
        return axios.post(`${baseUrl.sq}/v1/mobile/verify_code/send`, qs.stringify({
            action: "send",
            captcha_code,
            [type]: sendData,
            type: "sms",
            way: type,
            password
        }));
    },
     
    // 加入购物车 - 确认订单 - 有数组不能用qs.stringify序列化
    checkout (geohash, entities, shopId) {  
        return axios.post(`${baseUrl.sq}/v1/carts/checkout`, {
            come_from: "web",
            geohash,
            entities,
            restaurant_id: shopId
        });
    },
     
    // 获取备注信息
    getRemark (id, sig) {        
        return axios.get(`${baseUrl.sq}/v1/carts/${id}/remarks`, {
            params: {
                sig
            }
        });
    },
     
    // 获取收货地址列表
    getAddress (id, sig) {        
        return axios.get(`${baseUrl.sq}/v1/carts/${id}/addresses`, {
            params: {
                sig
            }
        });
    },
     
    // 添加地址
    postAddAddress (user_id, address, address_detail, geohash, name, phone, phone_bk, poi_type, sex, tag, tag_type) {        
        return axios.post(`${baseUrl.sq}/v1/users/${user_id}/addresses`, qs.stringify({
            address,
            address_detail,
            geohash,
            name,
            phone,
            phone_bk,
            poi_type,
            sex,
            tag,
            tag_type
        }));
    },
     
    // 删除地址
    deleteAddress (user_id, address_id) {        
        return axios.delete(`${baseUrl.sq}/v1/users/${user_id}/addresses/${address_id}`, qs.stringify({}));
    },
     
    // 搜索地址
    searchNearby (cityid, keyword) {        
        return axios.get(`${baseUrl.sq}/v1/pois`, {
            params: {
                type: 'nearby',
                city_id: cityid,
                keyword
            }
        });
    },
     
    // 下订单
    placeOrders (user_id, cart_id, address_id, description, entities, geohash, sig) {        
        return axios.post(`${baseUrl.sq}/v1/users/${user_id}/carts/${cart_id}/orders`, qs.stringify({
            address_id,
            come_from: "mobile_web",
            deliver_time: "",
            description,
            entities,
            geohash,
            paymethod_id: 1,
            sig
        }));
    },
     
    // 获取订单列表
    getOrderList (user_id, offset) {        
        return axios.get(`${baseUrl.sq}/bos/v2/users/${user_id}/orders`, {
            params: {
                limit: 10,
                offset,
            }
        });
    },
     
    // 获取订单详情
    getOrderDetail (user_id, order_id) {        
        return axios.get(`${baseUrl.sq}/bos/v1/users/${user_id}/orders/${order_id}/snapshot`);
    },
     
    // 重新发送订单验证码
    rePostVerify (cart_id, sig, type) {        
        return axios.post(`${baseUrl.sq}/v1/carts/${cart_id}/verify_code`, qs.stringify({
            sig,
            type
        }));
    },
     
    // 验证订单
    validateOrders (
        user_id,
        cart_id,
        address_id,
        description,
        entities,
        geohash,
        sig,
        validation_code,
        validation_token
    ) {        
        return axios.post(`${baseUrl.sq}/v1/users/${user_id}/carts/${cart_id}/orders`, qs.stringify({
            address_id,
            come_from: "mobile_web",
            deliver_time: "",
            description,
            entities,
            geohash,
            paymethod_id: 1,
            sig,
            validation_code,
            validation_token
        }));
    },
     
    // 付款请求
    payRequest (merchantOrderNo, user_id) {        
        return axios.get(`${baseUrl.sq}/payapi/payment/queryOrder`, {
            params: {
                merchantId: 5,
                merchantOrderNo,
                source: 'MOBILE_WAP',
                user_id,
                version: '1.0.0'
            }
        });
    },
     
    // 获取服务中心信息
    getService (merchantOrderNo, user_id) {        
        return axios.get(`${baseUrl.sq}/v3/profile/explain`);
    },
     
    // 兑换会员卡
    vipCart (id, number, password) {        
        return axios.post(`${baseUrl.sq}/member/v1/users/${id}/delivery_card/physical_card/bind`, qs.stringify({
            number,
            password
        }));
    },
     
    // 获取可用红包
    getHongbaoNum (id) {        
        return axios.get(`${baseUrl.sq}/promotion/v2/users/${id}/hongbaos?limit=20&offset=0`);
    },
     
    // 获取过期红包
    getExpired (id) {        
        return axios.get(`${baseUrl.sq}/promotion/v2/users/${id}/expired_hongbaos?limit=20&offset=0`);
    },
     
    // 兑换红包
    exChangeHongbao (id, exchange_code, captcha_code) {        
        return axios.post(`${baseUrl.sq}/v1/users/${id}/hongbao/exchange`, qs.stringify({
            params: {
                exchange_code,
                captcha_code,
            }
        }));
    },
     
    // 获取用户信息
    getUser () {        
        return axios.get(`${baseUrl.sq}/v1/user`, {
            params: {
                user_id: getStore('user_id')
            }
        });
    },
     
    // 手机号登录
    sendLogin (code, mobile, validate_token) {        
        return axios.post(`${baseUrl.sq}/v1/login/app_mobile`, qs.stringify({
            code,
            mobile,
            validate_token
        }));
    },
     
    // 获取个人中心里收货地址列表
    getAddressList (user_id) {        
        return axios.get(`${baseUrl.sq}/v1/users/${user_id}/addresses`);
    },
     
    // 个人中心里搜索地址
    getSearchAddress (keyword) {        
        return axios.get(`${baseUrl.sq}/v1/pois`, {
            params: {
                keyword,
                type:'nearby'
            }
        });
    },
     
    // 账号密码登录
    accountLogin (username, password, captcha_code) {        
        return axios.post(`${baseUrl.sq}/v2/login`, {
            username,
            password,
            captcha_code
        });
    },
     
    // 退出登录
    signout () {        
        return axios.get(`${baseUrl.sq}/v2/signout`);
    },
     
    // 改密码
    changePassword (username, oldpassWord, newpassword, confirmpassword, captcha_code) {        
        return axios.post(`${baseUrl.sq}/v2/changepassword`, qs.stringify({
            username,
            oldpassWord,
            newpassword,
            confirmpassword,
            captcha_code
        }));
    },
}

export default home;
